package com.cdut.logistics.action.datacentre;

import java.util.ArrayList;
import java.util.List;

import com.cdut.logistics.intercepter.system.AuthorityIntercepter;
import com.cdut.logistics.model.dao.datacentre.Area;
import com.cdut.logistics.service.impl.datacentre.AreaImpl;
import com.cdut.logistics.service.interf.datacentre.AreaService;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;

/**  
 * @ClassName: DeptController  
 * @Description: 区域管理控制类
 * @author wxt.xia
 * @date 2018年1月26日 下午3:28:25    
 */
//@Before(AuthorityIntercepter.class)
public class AreaController extends Controller {
	
	private AreaService areaService = new AreaImpl();
	/**
	 * 
	 * @Title: query  
	 * @Description: 根据区域名称查询区域
	 * @author wxt.xia
	 * @param json
	 * @throws
	 */
	public void query(){
		/*
		 * 解析json
		 */
		String name = getPara("area_name")+"%";
		List<Record> deptList = new ArrayList<Record>();
		try {
			 deptList = areaService.query(name);
			//System.out.println(deptList.get(0).getName());
		} catch (Exception e) {
			// TODO: handle exception
		}
		renderJson(deptList);
	}	
	
	/**
	 * 
	 * @Title: add  
	 * @Description: 新增区域
	 * @author wxt.xia
	 * @throws
	 */
	public void add(){
		/*
		 * 解析json
		 */
		
		//下面是测试数据，id需设置为自增长
		Area area = new Area();
		area.set("school_id", 1);
		area.set("name", "珙桐");
		
		try {
			areaService.add(area);
		} catch (Exception e) {
			
		}
	}
	
	/**
	 * 
	 * @Title: form  
	 * @Description: 修改信息
	 * @author wxt.xia
	 * @throws
	 */
	public void modify(){
		/*
		 * 解析json
		 */
		Area area = new Area();
		area.set("name", "芙蓉");
		area.set("id", 1);
		try {
			areaService.modify(area);
		} catch (Exception e) {
			
		}
	}
	
	/**
	 * 
	 * @Title: remove  
	 * @Description: 删除区域
	 * @author wxt.xia
	 * @throws
	 */
	public void remove(){
		int id = 3;
		try {
			areaService.remove(id);
		} catch (Exception e) {
			
		}
	}
}
